import { init } from '@aehyok/utils'
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { createRouter, createWebHashHistory } from 'vue-router'
import App from './App.vue'
import routes from './router'
import store from './store'

init()
let instance = null

function render(props: any = {}) {
  const { container } = props
  const router = createRouter({
    history: createWebHashHistory(),
    routes
  })

  instance = createApp(App)
  instance
    .use(ElementPlus, { locale: zhCn })
    .use(store)
    .use(router)
    .mount(container ? container.querySelector('#mapapp') : '#mapapp')
}
  console.log('独立运行')
// 独立运行时
if (!Object.prototype.hasOwnProperty.call(window, '__POWERED_BY_QIANKUN__')) {
  console.log('独立运行')
  render()
}

export async function bootstrap() {
  console.log('[vue] vue app bootstraped')
}

export async function mount(props: any) {
  console.log('[vue] props from main framework', props)

  render(props)
}

export async function unmount() {
  // instance.$destroy();
  // instance.$el.innerHTML = "";
  // instance = null;
}
